<?php	
	/*
	 * This class will hold all our MySQL Database-related functions! :)
	 * @var $dbhandle resource Database handle
	 */
	class Database
	{
		/*
		 * This will store our database connection
		 */
		private $dbhandle;
		/*
		 * This function connects to the Database
		 * @global $DBconf array Database configuration
		 */
		private function connect()
		{
			/*
			 * We need the global configuration
			 */
			global $DBconf;
			/*
			 * Connect to the database and save the resource in the var
			 */
			$this->dbhandle = mysql_connect($DBconf["server"], $DBconf["username"], $DBconf["password"]);
			/*
			 * Select the right database
			 */
			mysql_select_db($DBconf["dbname"], $this->dbhandle);
		}
		/*
		 * Close our database connection
		 */
		private function disconnect()
		{
			/*
			 * Close it right away :)
			 */
			mysql_close($this->dbhandle);
		}
		/*
		 * Executes a SQL-Statement
		 * @param $sql string SQL-Statement to execute
		 */
		public function exec($sql)
		{
			/*
			 * Execute our query
			 */
			mysql_query($sql, $this->dbhandle);
		}
		/*
		 * Queries the database
		 * @param $sql string SQL-Query to execute
		 * @var $query
		 * @var $i integer
		 * @var $result array
		 * @return array Results of the query
		 */
		public function query($sql)
		{
			/*
			 * Execute our query and save the results
			 */
			$query = mysql_query($sql, $this->dbhandle);
			/*
			 * Initialize the counter with 0
			 */
			$i = 0;
			/*
			 * Save the results in an Array
			 */
			$result = array();
			/*
			 * While loop to fetch all rows
			 */
			while ($row = mysql_fetch_array($query))
			{
				/*
				 * Add row to the results-array
				 */
				$result[$i] = $row;
				/*
				 * Increment our counter
				 */
				$i++;
			}
			/*
			 * Return the results
			 */
			return $result;
		}
		/*
		 * Constructor for our class
		 */
		public function __construct()
		{
			/*
			 * Connect to the Database
			 */
			$this->connect();
		}
		/*
		 * Destructor for our class
		 */
		public function __destruct()
		{
			/*
			 * Close the connection to the database 
			 */ 
			$this->disconnect();
		}
	}
?>